package com.cmsz.collection.config;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author liupeng
 * @date 2020/1/6
 * @description kafka生产者config，用于测试kafka实时消费能量
 */

@Configuration
public class kafkaProducerConfig {


    @Value("${spring.kafka.producer.key-serializer}")
    private String keyDeserializer;

    @Value("${spring.kafka.producer.value-serializer}")
    private String valueDeserializer;

    @Value("${spring.kafka.bootstrap-servers}")
    private String service;



    @Bean(value = "kafkaProducer")
    public Producer createProducer(){

        Properties properties = new Properties();

        properties.put("bootstrap.servers", service);
        properties.put("key.serializer", keyDeserializer);
        properties.put("value.serializer", valueDeserializer);

        Producer producer = new KafkaProducer(properties);

        return producer;


    }


}
